package com.gl.library.widget.onclicklistener;

import android.view.View;
import android.widget.AdapterView;

import java.util.Calendar;

public abstract class OnItemFastClickListener implements AdapterView.OnItemClickListener {

    // 防止快速点击默认等待时长为900ms
    private static final int DEFAULT_DELAY_TIME = 900;

    private long mDelayTime;

    private static long lastClickTime;

    public OnItemFastClickListener(long delayTime) {
        this.mDelayTime = delayTime;
    }

    public OnItemFastClickListener() {
        this.mDelayTime = DEFAULT_DELAY_TIME;
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        long currentTime = Calendar.getInstance().getTimeInMillis();
        if (currentTime - lastClickTime > mDelayTime) {
            lastClickTime = currentTime;
            onItemFastClick(parent, view, position, id);
        }
    }

    protected abstract void onItemFastClick(AdapterView<?> parent, View view, int position, long id);
}
